<?php
if(!defined('MY_ROOT'))
{throw new Exception('Access Denied');}
$code=$_G['hwnd']['seccode'];
if($_POST['submit']=='yes'){
$result=$code->check($_POST['recaptcha_response_field'],$_POST['recaptcha_challenge_field']);
if(!$result)
{
showmessage('error',_('seccode_error'),false,'member.php?mod=register');
throw new Exception();
}
$member=$_G['hwnd']['member'];
if($_POST['username']!=strip_tags($_POST['username']))
{
showmessage('error',_('username_invalid'),false,'member.php?mod=register');
throw new Exception();
}
if(!$member->check_avail(trim($_POST['username'])))
{
showmessage('error',_('user_exists'),false,'member.php?mod=register');
throw new Exception();
}
if($_POST['password']!=$_POST['rpassword']){
showmessage('error',_('password_dismatch'),false,'member.php?mod=register');
throw new Exception();
}
if(!check_email($_POST['email']))
{
showmessage('error',_('email_invalid'),false,'member.php?mod=register');
throw new Exception();
}
$emailc=DB::select('member','`email`='.DB::get_str($_POST['email']),'`id`',true);
if($emailc)
{
showmessage('error',_('email_exists'),false,'member.php?mod=register');
throw new Exception();
}
$extra['name']=isset($_POST['name']) ? trim($_POST['name']) : $_POST['username'];
$extra['address']=isset($_POST['address']) ? trim($_POST['address']) : '';
$extra['phone']=isset($_POST['phone']) ? trim($_POST['phone']) : '';
$extra['contact']=isset($_POST['contact']) ? trim($_POST['contact']) : '';
$username=trim(strip_tags($_POST['username']));
$member->register($username,$_POST['password'],trim($_POST['email']),$extra);
showmessage('success',_('register_ok'),false,'member.php');
}
elseif($_POST['submit']=='check')
{
$member=$_G['hwnd']['member'];
$smarty=$_G['hwnd']['smarty'];
switch($_POST['action'])
{
case 'username':
if($member->check_avail($_POST['username']))
{
$smarty->assign('content','ok',true);
}else{
$smarty->assign('content','na',true);
}
break;
case 'email':
$emailc=DB::select('member','`email`='.DB::get_str($_POST['email']),'`id`',true);
if($emailc)
{
$smarty->assign('content','na',true);
}else{
$smarty->assign('content','ok',true);
}
break;
default:
$smarty->assign('content','ok',true);
}
$smarty->display('common/ajax_blank.tpl');
}else{
$smarty=$_G['hwnd']['smarty'];
$smarty->assign('recaptcha',$code->recaptcha_get_html());
$smarty->display('member/register.tpl');
}
?>
